//
//  MBTool.m
//  小团购
//
//  Created by 樊荣海 on 15/2/2.
//  Copyright (c) 2015年 樊荣海. All rights reserved.
//

#import "MBTool.h"

@implementation MBTool
static MBProgressHUD *HUD;

+ (void)showHUD:(NSString *)msg inView:(UIView *)view {
    
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    HUD.dimBackground = NO;
    HUD.labelText = msg;
    
    [HUD show:YES];
}

+ (void)showHUDWithText:(NSString *)msg ImageName:(NSString *)imgName{
    
    HUD = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    
    HUD.dimBackground = NO;
    HUD.labelText = msg;
    HUD.mode = MBProgressHUDModeCustomView;
    HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imgName]];
    HUD.yOffset = -20.f;
    [HUD showAnimated:YES whileExecutingBlock:^{
        sleep(2);
    } completionBlock:^{
        
        [HUD removeFromSuperview];
        
        HUD = nil;
    }];
    
    
}
+ (void)removeHUD{
    
    [HUD hide:YES];
    [HUD removeFromSuperViewOnHide];
}

//ronghai
+ (void)showHUDWithText:(NSString *)msg inView:(UIView *)view Delay:(int)delayTime {
    
    //显示提示信息
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.userInteractionEnabled = NO;
    // Configure for text only and offset down
    hud.mode = MBProgressHUDModeText;
    hud.dimBackground = NO;
    hud.labelText = msg;
    //    hud.margin = 10.f;
    //    hud.yOffset = iPhone5?50.f:0.f;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:delayTime];
}

//+ (void)showTextOnly:(NSString *)text {
//    UIView *view = [[UIApplication sharedApplication].delegate window];
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    hud.removeFromSuperViewOnHide =YES;
//    hud.animationType = MBProgressHUDAnimationFade;
//    hud.mode = MBProgressHUDModeText;
//    hud.labelText = text;
//    hud.removeFromSuperViewOnHide = YES;
//    [hud hide:YES afterDelay:1.5f];
//}


@end
